package src.threadlocal;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 30个线程打印日期
 */
public class ThreadLocalNormalUsage01 {
    public String date(int seconds) {
        //参数的定位是毫秒，从1970年1月1日00:00:00到现在的秒数
        Date date = new Date(seconds * 1000L);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
    public static void main(String[] args) {
        for (int i = 0; i < 30; i++) {
            int finalI = i;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String date = new ThreadLocalNormalUsage01().date(finalI);
                    System.out.println(date);
                }
            }).start();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
